/*
 * @Author: xiawei.lv
 * @Date: 2021-07-31 10:02:11
 * @Description: 权限模块
 * @FilePath: \GoodsManagement\src\commonLogical\rolePermissions\rolePermissionsLogical.ts
 */
/**
 * 负责用户模块的同学注意啦，要和做路由的同学交流好
 * 我给你的是一个list
 * 查询有什么角色遍历一下就好了
 * 你只需要在你的用户类里添加一个字段，将rolePermissionsList中你要选择的角色中的name值保存下来
 * 查询权限列表时只需在rolePermissionsList中查询对应的name，获取对应的可执行权限列表
 *
 * 用户模块同学示例写法
 * 
 * import {roles} from "../commonLogical/rolePermissions/rolePermissionsLogical"
 * console.log(roles)
 *
 */

 import { gradingOfAuthority } from "../../pages/data/Permissions/Permissions";
 /**
  * 下面的是权限模块的数据类
  */
 class RolePermissions {
   constructor(
     public name: string,
     public description: string,
     public executablePermission: string[] //可执行权限列表
   ) {}
 }
 
 class Permissions {
   constructor(public id:number,public name: string, public level: number, public path: string) {}
 }
 
 /**
  * 多级树
  */
 interface Node {
   name: string;
   level: number;
   path: string;
   children: Array<Node>;
 }
 
 let getPermissionsArray = () => {
   let permissionsArray = new Array();
   let data = gradingOfAuthority;
 
   let nodes = new Array();
   for (let i = 0; i < data.length; i++) {
     nodes.push(data[i]);
   }
 
   let count=0
   while (nodes.length > 0) {
     let child = nodes.shift();
     count++;
     permissionsArray.push(new Permissions(count,child.name, child.level, child.path));
     if (child.children !== undefined) {
       child.children.forEach((element: any) => {
         nodes.push(element);
       });
     }
   }
 
   return permissionsArray;
 };
 
 /**
  * 返回权限列表数组
  */
 export let permissionsArray: Array<Permissions> = getPermissionsArray();
 
 /**
  * 角色列表
  */
 class RolePermissionsList {
   constructor(public array: Array<RolePermissions>) {
     this.init();
   }
   init() {
     this.add("主管", "技术负责人", ["s","ssss"]);
     this.add("测试角色", "测试角色描述", ["s","ss"]);
     this.add("测试角色2", "测试描述12", ["s"]);
     this.add("test", "test", ["s"]);
   }
   add(name: string, description: string, executablePermission: string[]) {
     this.array.push(
       new RolePermissions(name, description, executablePermission)
     );
   }
   del(index: number) {
     this.array.splice(index, 1);
   }
 }
 
 let rolePermissionsList = new RolePermissionsList(new Array<RolePermissions>());
 
 
 export let roles=rolePermissionsList.array
 